package com.skycong.hello77.activity.toast;

import android.content.Context;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import com.skycong.hello77.R;
import com.skycong.hello77.activity.dialog.DialogActivity;
import com.skycong.hello77.custom.TestActivity;
import com.skycong.hello77.datepicker.DatePickerDialog;

/**
 * 测试toast
 */
public class ToastActivity extends AppCompatActivity implements View.OnClickListener,DatePickerDialog.SelectTimeDialogListener {
    public DatePickerDialog datePicker;
    public Context context;
    public TextView selectTime;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_toast);
        context = this;
        Button default_toast = (Button) findViewById(R.id.default_toast);
        default_toast.setOnClickListener(this);
        Button chang_position = (Button) findViewById(R.id.chang_position);
        chang_position.setOnClickListener(this);
        Button with_pic = (Button) findViewById(R.id.with_pic);
        with_pic.setOnClickListener(this);
        Button free_toast = (Button) findViewById(R.id.free_toast);
        free_toast.setOnClickListener(this);
        datePicker = new DatePickerDialog(context,this);
        selectTime = (TextView) findViewById(R.id.select_time);

    }

    @Override
    public void onClick(View v) {
        int butId = v.getId();

        switch (butId) {
            case R.id.default_toast: {
//                Toast.makeText(ToastActivity.this, "默认提示", Toast.LENGTH_SHORT).show();
//                datePicker.show();
                Intent intent = new Intent(ToastActivity.this,TestActivity.class);
                startActivity(intent);
                break;
            }
            case R.id.chang_position: {

//                Toast toast = Toast.makeText(ToastActivity.this, "改变位置的Toast", Toast.LENGTH_SHORT);
//                /*
//                 * gravity 对齐样式
//                 * xoffset 水平偏移
//                 * yoffset 垂直偏移
//                 * */
//                toast.setGravity(Gravity.RIGHT, 0, 0);
//                toast.show();
                break;
            }
            case R.id.with_pic: {
                Toast toast = Toast.makeText(ToastActivity.this, "带图片的Toast", Toast.LENGTH_SHORT);
                /*
                 * gravity 对齐样式
                 * xoffset 水平偏移
                 * yoffset 垂直偏移
                 * */
                toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
                LinearLayout linearLayout = (LinearLayout) toast.getView();
                ImageView imageView = new ImageView(ToastActivity.this);
                imageView.setImageResource(R.mipmap.hahaha);
                // index 表示图片所处的位置，从上到下 从0开始索引，o最上边
                linearLayout.addView(imageView,0);
                toast.show();
                break;
            }
            case R.id.free_toast: {
                LayoutInflater inflater = LayoutInflater.from(ToastActivity.this);
                View toast_view = inflater.inflate(R.layout.toast_layout,null);
                Toast toast = new Toast(ToastActivity.this);
                toast.setView(toast_view);
                toast.setDuration(Toast.LENGTH_LONG);
                toast.show();
                break;
            }
        }
    }

    @Override
    public void onCancel() {
         datePicker.hide();
    }

    @Override
    public void selectTimeConfirm(String timeStr) {
        selectTime.setText(timeStr);
        datePicker.hide();
    }
}
